package org.deadline.model.config;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.baseapp.BaseEntity;
import org.deadline.model.user.Person;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;

@Entity
public class StateProvince extends BaseEntity  implements Serializable {

    @Size(min = 3, max = 100)
    private String stateCode;

    @NotNull
    @Size(min = 3, max = 100)
    private String stateName;

    @Size(min = 3, max = 100)
    private String stateCapital;

    @ManyToOne
    private Person createdBy;

    @ManyToOne
    private Country country;

    @Id
	@Column(name="id",unique=true,nullable=false)
	@SequenceGenerator(name="state_province_seq_gen",sequenceName="state_province_seq")
	@GeneratedValue(generator="state_province_seq_gen",strategy=GenerationType.TABLE)
	@Generated(GenerationTime.INSERT)
	private Long id;

    
	public String getStateCode() {
        return this.stateCode;
    }

	public void setStateCode(String stateCode) {
        this.stateCode = stateCode;
    }

	public String getStateName() {
        return this.stateName;
    }

	public void setStateName(String stateName) {
        this.stateName = stateName;
    }

	public String getStateCapital() {
        return this.stateCapital;
    }

	public void setStateCapital(String stateCapital) {
        this.stateCapital = stateCapital;
    }

	public Person getCreatedBy() {
        return this.createdBy;
    }

	public void setCreatedBy(Person createdBy) {
        this.createdBy = createdBy;
    }

	public Country getCountry() {
        return this.country;
    }

	public void setCountry(Country country) {
        this.country = country;
    }

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}


	private static final long serialVersionUID = 1L;

	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	public static StateProvince fromJsonToStateProvince(String json) {
        return new JSONDeserializer<StateProvince>().use(null, StateProvince.class).deserialize(json);
    }

	public static String toJsonArray(Collection<StateProvince> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<StateProvince> fromJsonArrayToStateProvinces(String json) {
        return new JSONDeserializer<List<StateProvince>>().use(null, ArrayList.class).use("values", StateProvince.class).deserialize(json);
    }

	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}
